package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.sxm.yiwei.R;
import com.sxm.yiwei.beans.Link;

import java.util.ArrayList;

/**
 * Created by KuKa on 2017/5/30.
 * 联系人列表
 */

public class LinkSlideAdapter extends BaseAdapter {

    public ArrayList<Link.DataBean> linkList;
    private Context context;
    private String name;
    private String phone;
    private String address;
    private Link.DataBean dataBean;

    public LinkSlideAdapter(Context context, ArrayList<Link.DataBean> linkList) {
        this.context=context;
        this.linkList=linkList;
    }

    @Override
    public int getCount() {


        return linkList.size();

    }

    @Override
    public Object getItem(int position) {

        return linkList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

   @Override
    public boolean hasStableIds() {
        //getCheckedItemIds()方法要求此处返回为真
        return true;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        ViewHolder viewHolder;
        if(convertView==null) {
            view = View.inflate(context, R.layout.item_slide_delete_edit, null);
            viewHolder=new ViewHolder();
            viewHolder.linkPhone=(TextView)view.findViewById(R.id.send_linkphone);
            viewHolder.linkName=(TextView)view.findViewById(R.id.send_linkname);
            viewHolder.linkAddress = (TextView) view.findViewById(R.id.send_linkaddress);
            viewHolder.tvDelete=(TextView)view.findViewById(R.id.delete);
            viewHolder.tvEdit=(TextView)view.findViewById(R.id.tvEdit);
            viewHolder.itembox = (CheckBox) view.findViewById(R.id.item_box);
            view.setTag(viewHolder);//store up viewHolder
        }else {
            view=convertView;
            viewHolder=(ViewHolder)view.getTag();
        }
            dataBean = linkList.get(position);

        String id = linkList.get(position).getId();

        viewHolder.linkPhone.setText(linkList.get(position).getPhone());
        viewHolder.linkAddress.setText(linkList.get(position).getAddress());
        viewHolder.linkName.setText(linkList.get(position).getName());

        notifyDataSetChanged();
        return view;
    }

    public class ViewHolder{
        TextView linkAddress,tvEdit,tvDelete,linkName,linkPhone;
       public CheckBox itembox;

    }


}